﻿using Prism.Regions;
using Prism.Services.Dialogs;
using System.Collections.ObjectModel;
using Unity;

namespace SmartPlant.Core.Mvvm
{
    /// <summary>
    /// 用于绑定到GridView、TreeView控件的Region对象。
    /// </summary>
    /// <typeparam name="T">绑定的实体对象。</typeparam>
    public abstract class ListRegionViewModel<T> : DynamicColumnRegionViewModel
        where T : class, new()
    {
        private T _selectObj;
        private ObservableCollection<T> _list;

        /// <summary>
        /// 默认的构造函数。
        /// </summary>
        /// <param name="regionManager"><see cref="IRegionManager"/>对象。</param>
        /// <param name="unityContainer"><see cref="IUnityContainer"/>对象。</param>
        public ListRegionViewModel(
            IRegionManager regionManager,
            IUnityContainer unityContainer,
            IDialogService dialogService) :
            base(regionManager, unityContainer, dialogService)
        {
            _list = new ObservableCollection<T>();
        }


        #region 属性
        /// <summary>
        /// 用于绑定到GridView、TreeView控件的集合数据。
        /// </summary>
        public ObservableCollection<T> DataList
        {
            get { return _list; }
            set { SetProperty(ref _list, value); }
        }

        /// <summary>
        /// 获取当前GridView、TreeView控件的选择对象。
        /// </summary>
        public T SelectObj
        {
            get { return _selectObj; }
            set { SetProperty(ref _selectObj, value); }
        }
        #endregion
    }
}
